<template>
  <div class="action">
    <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" />
      <van-goods-action-icon icon="shopping-cart" text="购物车" v-tap="{methods:cart}" />
      <van-goods-action-button color="#eeeeee" v-tap="{methods:tap}" type="warning" text="加入购物车" />
      <van-goods-action-button color="#000000" v-tap="{methods:buy}" type="danger" text="立即购买" />
    </van-goods-action>
    <van-popup v-model="show" position="bottom" closeable :style="{ height: '50%' }">
      <div class="container">
        <div class="imgwrap">
          <img :src="list.pimg" alt />
        </div>
        <div class="detail">
          <p>￥{{list.pprice}}</p>
          <p>
            <van-tag type="warning">优惠</van-tag>
            <span>
              组合购买更优惠
              <i class="iconfont icon-jiantou"></i>
            </span>
          </p>
        </div>
        <div class="steppers">
          <van-stepper v-model="value" integer />
        </div>
      </div>
      <button class="btn" v-tap="{methods:add}">{{confirm}}</button>
    </van-popup>
  </div>
</template>

<script>
import * as api from "@/api/getProlist.js";
import { Dialog } from "vant";

export default {
  name: "ProdAction",
  data() {
    return {
      active: 0,
      show: false,
      value: 1,
      confirm: "确认下单",
      list: {}
    };
  },
  methods: {
    tap() {
      this.show = !this.show;
      this.confirm = "确认加入";
    },
    buy() {
      this.show = !this.show;
      this.confirm = "确认下单";
    },
    add() {
      //添加
      if (localStorage.getItem("token") == null) {
        Dialog.alert({
          message: "请先登录哦!"
        });
        this.$router.push("/my");
      } else {
        this.show = !this.show;
        var pid = this.list.pid;
        console.log(this.list.pid);
        var cnumber = document.getElementsByTagName("input")[0].value;
        api.addCart({ cnumber: cnumber, pid: pid }).then(data => {
          // console.log(data.data);
        });
      }
    },
    cart() {
      this.$router.push("/cart");
    }
  },
  mounted() {
    api.getProDel({ pid: this.$route.query.id }).then(data => {
      this.list = data.data.result[0];
      // console.log(this.list);
    });
  }
};
</script>

<style scoped>
.van-goods-action {
  z-index: 100;
}
.van-button--warning {
  color: #000 !important;
}
.btn {
  width: 100%;
  height: 80px;
  background: #000;
  color: #fff;
  line-height: 80px;
  font-size: 30px;
  text-align: center;
  border: 0;
  position: fixed;
  bottom: 0;
  left: 0;
}
.van-popup {
  padding: 20px;
  box-sizing: border-box;
}
.imgwrap {
  width: 260px;
  height: 260px;
  border: solid 1px #cecece;
  overflow: hidden;
  float: left;
}
.imgwrap img {
  width: 98%;
  margin: 1% 0 0 1%;
}
.container {
  width: 100%;
  height: 270px;
  overflow: hidden;
}
.steppers {
  /* margin-top: 50px;
  margin-left: 30px;
  float: left; */
}
.detail {
  width: 375px;
  float: left;
  margin-left: 30px;
}
.detail p span {
  margin-left: 10px;
}
.detail p i {
  font-size: 24px;
}
</style>